<?php
class Express_model extends BZ_Model
{
    protected $table  = 'express';

    public function page_list($page_num, $num, $params)
    {
        $this->db->select('id,name,company,create_at');
        $this->db->from($this->table);

        if(!empty($params['keyWord'])){
            $this->db->like('name', $params['keyWord']);
            $this->db->or_like('company', $params['keyWord']);
        }

        $this->db->order_by('id', 'ASC');
        $this->db->limit($page_num, $num);
        return $this->db->get();
    }

    public function total($params)
    {
        $this->db->select('*');
        $this->db->from($this->table);
        if(!empty($params['keyWord'])){
            $this->db->like('name', $params['keyWord']);
            $this->db->or_like('company', $params['keyWord']);
        }
        return $this->db->count_all_results();
    }

    public function delete($id)
    {
        $this->db->where('id', $id);
        return $this->db->delete($this->table);
    }

    public function findById($id)
    {
        $this->db->select('id,name,company');
        $this->db->from($this->table);
        $this->db->where('id', $id);

        $this->db->limit(1);
        return $this->db->get();
    }

    public function findByName($company)
    {
        $this->db->select('id,name,company');
        $this->db->from($this->table);
        $this->db->where('company', $company);
        $this->db->limit(1);
        return $this->db->get();
    }

    public function isExist($name, $company)
    {
        $this->db->select('id,name,company');
        $this->db->from($this->table);
        $this->db->where('name', $name);
        $this->db->or_where('company', $company);

        return $this->db->get();
    }

}
